#include "MonsterFactory.h"
#include "SpriteStar.h"
#include "SpriteBlackCloud.h"
#include "SpriteFlashing.h"
#include "SpriteArmor.h"
#include "SpriteSafecap.h"
#include "SpriteEagle.h"
#include "SpritePlane.h"
#include "SpriteGhost.h"
#include "CGlobal.h"
using namespace cocos2d;
MonsterFactory::MonsterFactory(void)
{
}

MonsterFactory::~MonsterFactory(void)
{
}

bool MonsterFactory::getMonsterName( MONSTER_SUB_TAG tag,std::string strName[],int &nNum )
{
	bool bRet=false;
	switch(tag)
	{
	case TAG_NONE:
		break;
	case TAG_STAR:
		{
			std::string strArray[]={"star.png"};
			int nRealNum=sizeof(strArray)/sizeof(std::string);
			if (nRealNum<=nNum)
			{
				for (int i=0;i<nRealNum;i++)
				{
					strName[i]=strArray[i];
				}
				bRet=true;
			}
			nNum=nRealNum;
		}
		break;
	case TAG_BLACKCLOUD:
		{
			std::string strArray[]={"blackcloud.png"};
			int nRealNum=sizeof(strArray)/sizeof(std::string);
			if (nRealNum<=nNum)
			{
				for (int i=0;i<nRealNum;i++)
				{
					strName[i]=strArray[i];
				}
				bRet=true;
			}
			nNum=nRealNum;
		}
		break;
	case TAG_EAGLE:
		{
			std::string strArray[]={"eagle.png"};
			int nRealNum=sizeof(strArray)/sizeof(std::string);
			if (nRealNum<=nNum)
			{
				for (int i=0;i<nRealNum;i++)
				{
					strName[i]=strArray[i];
				}
				bRet=true;
			}
			nNum=nRealNum;
		}
		break;
	case TAG_FLASHING:
		{
			std::string strArray[]={"flashing.png"};
			int nRealNum=sizeof(strArray)/sizeof(std::string);
			if (nRealNum<=nNum)
			{
				for (int i=0;i<nRealNum;i++)
				{
					strName[i]=strArray[i];
				}
				bRet=true;
			}
			nNum=nRealNum;
		}
		break;
	case TAG_PLANE:
		{
			std::string strArray[]={"plane.png"};
			int nRealNum=sizeof(strArray)/sizeof(std::string);
			if (nRealNum<=nNum)
			{
				for (int i=0;i<nRealNum;i++)
				{
					strName[i]=strArray[i];
				}
				bRet=true;
			}
			nNum=nRealNum;
		}
		break;
	case TAG_SAFECAP:
		{
			std::string strArray[]={"safecap.png"};
			int nRealNum=sizeof(strArray)/sizeof(std::string);
			if (nRealNum<=nNum)
			{
				for (int i=0;i<nRealNum;i++)
				{
					strName[i]=strArray[i];
				}
				bRet=true;
			}
			nNum=nRealNum;
		}
		break;
	case TAG_ARMOR:
		{
			std::string strArray[]={"armor.png"};
			int nRealNum=sizeof(strArray)/sizeof(std::string);
			if (nRealNum<=nNum)
			{
				for (int i=0;i<nRealNum;i++)
				{
					strName[i]=strArray[i];
				}
				bRet=true;
			}
			nNum=nRealNum;
		}
		break;
	case TAG_GHOST:
		{
			std::string strArray[]={"ghost.png"};
			int nRealNum=sizeof(strArray)/sizeof(std::string);
			if (nRealNum<=nNum)
			{
				for (int i=0;i<nRealNum;i++)
				{
					strName[i]=strArray[i];
				}
				bRet=true;
			}
			nNum=nRealNum;
		}
		break;
	default:
		break;
	}
	return bRet;
}

SpriteMonster * MonsterFactory::getMonster( MONSTER_SUB_TAG tag )
{
	std::string *pStringArray=NULL;
	std::string strArray[6];
	bool bAlloc=false;
	int nSize=sizeof(strArray)/sizeof(std::string);
	if (!getMonsterName(tag,strArray,nSize))
	{
		pStringArray=new std::string[nSize];
		if (!pStringArray)
		{
			return NULL;
		}
		bAlloc=true;
		if (!getMonsterName(tag,pStringArray,nSize))
		{
			return NULL;
		}
	}
	else
	{
		pStringArray=strArray;
	}

	SpriteMonster *pMonster=NULL;
	switch(tag)
	{
	case TAG_NONE:
		break;
	case TAG_STAR:
		pMonster=SpriteStar::node(pStringArray,nSize,0.1f,true);
		break;
	case TAG_BLACKCLOUD:
		pMonster=SpriteBlackCloud::node(pStringArray,nSize,0.1f,true);
	    break;
	case TAG_EAGLE:
		pMonster=SpriteEagle::node(pStringArray,nSize,0.1f,true);
	    break;
	case TAG_FLASHING:
		pMonster=SpriteFlashing::node(pStringArray,nSize,0.1f,true);
		break;
	case TAG_PLANE:
		pMonster=SpritePlane::node(pStringArray,nSize,0.1f,true);
		break;
	case TAG_SAFECAP:
		pMonster=SpriteSafecap::node(pStringArray,nSize,0.1f,true);
	    break;
	case TAG_ARMOR:
		pMonster=SpriteArmor::node(pStringArray,nSize,0.1f,true);
	    break;
	case TAG_GHOST:
		pMonster=SpriteGhost::node(pStringArray,nSize,0.1f,true);
		break;
	default:
	    break;
	}
	if (bAlloc)
	{
		if (pStringArray)
		{
			delete []pStringArray;
			pStringArray=NULL;
		}
	}
	return pMonster;
}

cocos2d::CCSize MonsterFactory::getSize( MONSTER_SUB_TAG tag,CCSize scaleSize )
{
	CCSize size;
	switch(tag)
	{
	case TAG_NONE:
		size.setSize(0,0);
		break;
	case TAG_STAR:
		size.setSize(CGlobal::GetRatioX()*100*scaleSize.width,CGlobal::GetRatioY()*100*scaleSize.height);
		break;
	case TAG_BLACKCLOUD:
		size.setSize(CGlobal::GetRatioX()*100*scaleSize.width,CGlobal::GetRatioY()*100*scaleSize.height);
		break;
	case TAG_EAGLE:
		size.setSize(CGlobal::GetRatioX()*100*scaleSize.width,CGlobal::GetRatioY()*100*scaleSize.height);
		break;
	case TAG_FLASHING:
		size.setSize(CGlobal::GetRatioX()*100*scaleSize.width,CGlobal::GetRatioY()*100*scaleSize.height);
		break;
	case TAG_PLANE:
		size.setSize(CGlobal::GetRatioX()*100*scaleSize.width,CGlobal::GetRatioY()*100*scaleSize.height);
		break;
	case TAG_SAFECAP:
		size.setSize(CGlobal::GetRatioX()*100*scaleSize.width,CGlobal::GetRatioY()*100*scaleSize.height);
		break;
	case TAG_ARMOR:
		size.setSize(CGlobal::GetRatioX()*100*scaleSize.width,CGlobal::GetRatioY()*100*scaleSize.height);
		break;
	case TAG_GHOST:
		size.setSize(CGlobal::GetRatioX()*100*scaleSize.width,CGlobal::GetRatioY()*100*scaleSize.height);
		break;
	}

	return size;
}